package com.fulu.game.bi.controller.play;

import com.fulu.game.bi.entity.bo.channel.GameOverviewListBO;
import com.fulu.game.bi.entity.dto.GameOverviewListDTO;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.common.NameMsgVO;
import com.fulu.game.bi.redis.service.play.GameOverviewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 游戏陪玩-总览
 */
@RestController
@RequestMapping("/api/play/overview")
@Slf4j
public class GameOverviewController {
    @Autowired
    private GameOverviewService gameOverviewService;

    /**
     * 游戏陪玩-总览-实时
     */
    @RequestMapping("/realtime")
    public Result realtime() {
        return Result.success().data(gameOverviewService.realtime());
    }

    /**
     * 游戏陪玩-总览-列表
     */
    @RequestMapping("/list")
    public Result list(GameOverviewListDTO dto) {
        GameOverviewListBO bo = new GameOverviewListBO();
        BeanUtils.copyProperties(dto, bo);
        return Result.success().data(gameOverviewService.list(bo));
    }

    /**
     * 游戏陪玩-总览-折线图
     */
    @RequestMapping("/line-chart")
    public Result lineChart() {
        Map<String, String> cacheMap = new LinkedHashMap<>();
        cacheMap.put("新增陪玩师", "newAddPalyeeNum");
        cacheMap.put("活跃陪玩师", "livelyPlayeeNum");
        cacheMap.put("接单陪玩师", "orderPlayeeNum");
        cacheMap.put("退款陪玩师", "refundPlayeeNum");
        cacheMap.put("下单人数", "orderUserNum");
        cacheMap.put("下单次数", "orderNum");
        cacheMap.put("退款人数", "refundUserNum");
        cacheMap.put("退款次数", "refundNum");
        cacheMap.put("下单金额", "orderMoneyAll");
        cacheMap.put("下单时长", "orderDurationTime");
        cacheMap.put("优惠券使用人数", "couponUserNum");
        cacheMap.put("优惠券使用金额", "couponMoneyAll");
        cacheMap.put("打赏人数", "rewardUserNum");
        cacheMap.put("打赏次数", "rewardNum");
        cacheMap.put("打赏金额", "rewardMoneyAll");
        List<NameMsgVO> list = cacheMap.entrySet().stream()
                .map(entry -> {
                    NameMsgVO idNameVO = new NameMsgVO();
                    idNameVO.setName(entry.getValue());
                    idNameVO.setMsg(entry.getKey());
                    return idNameVO;
                })
                .collect(Collectors.toList());

        return Result.success().data(list).msg("获取成功");
    }

    /**
     * 游戏陪玩-总览-导出
     */
    @RequestMapping("/export")
    public void export(GameOverviewListDTO dto) {
        GameOverviewListBO bo = new GameOverviewListBO();
        BeanUtils.copyProperties(dto, bo);
        gameOverviewService.export(bo);
    }

}
